View Javadoc

1   /*
2       Copyright 2007-2014 TSB, http://www.tsbtecnologias.es
3       Technologies for Health and Well-being - Valencia, Spain
4   
5       See the NOTICE file distributed with this work for additional
6       information regarding copyright ownership
7   
8       Licensed under the Apache License, Version 2.0 (the "License");
9       you may not use this file except in compliance with the License.
10      You may obtain a copy of the License at
11  
12        http://www.apache.org/licenses/LICENSE-2.0
13  
14      Unless required by applicable law or agreed to in writing, software
15      distributed under the License is distributed on an "AS IS" BASIS,
16      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17      See the License for the specific language governing permissions and
18      limitations under the License.
19   */
20  /**
21   * x073 Continua agent publisher (agent events will be published over uAAL bus)
22   * 
23   * @author Angel Martinez-Cavero
24   * @version 0
25   *  
26   * TSB Technologies for Health and Well-being
27   */
28  
29  // Package
30  package org.universAAL.lddi.manager.publisher;
31  
32  // Imports
33  import java.awt.event.WindowAdapter;
34  import java.awt.event.WindowEvent;
35  
36  import javax.swing.JDialog;
37  
38  import org.osgi.framework.Bundle;
39  import org.osgi.framework.BundleActivator;
40  import org.osgi.framework.BundleContext;
41  import org.osgi.framework.BundleException;
42  import org.universAAL.lddi.manager.gui.GUI;
43  import org.universAAL.middleware.container.ModuleContext;
44  import org.universAAL.middleware.container.osgi.uAALBundleContainer;
45  
46  
47  
48  // Main class
49  public class Activator implements BundleActivator {
50  	
51  //	/Continua Health Manager|http://www.tsbtecnologias.es|http://ontologies.universAAL.com/CONTINUAHEALTHMANAGERUI.owl#ContinuaManager
52  
53  	// Attributes    
54  	/** Main GUI object */
55  	private GUI gui = null;	
56  	
57  //	/** Bundle context object */
58  //	private BundleContext ctx = null;	
59  	
60  	private ModuleContext mdlContext;
61  	private BundleContext bndContext;
62  	private ServiceProvider service;
63  	public static boolean dllReadyLatch = true;
64  	
65  	// Methods
66  	/** Start */
67  	public void start(BundleContext context) throws Exception {	
68  		mdlContext = uAALBundleContainer.THE_CONTAINER
69  				.registerModule(new Object[] { context });				
70  		// Create and show main GUI frame
71  		bndContext = context;		
72  		gui = new GUI(bndContext);								
73  		gui.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);			
74  		gui.addWindowListener(new WindowAdapter() {				
75  			public void windowClosing(WindowEvent e) {			
76  				gui.setVisible(false);
77  			}
78  		});
79  		//TODO cambiar para la demo true -> false
80  		gui.setVisible(false);		
81  		// Service callee
82  		service = new ServiceProvider(mdlContext,gui);		
83  	}
84  
85  	/** Stop */
86  	public void stop(BundleContext arg0) throws Exception {		
87  		gui.setVisible(false);
88  		dllReadyLatch = true;
89  		//gui.stopGUI();		
90  //		bndContext = null;
91  //		mdlContext = null;
92  	}	
93  	
94  	void stopSafe(final Bundle bundle) {		
95  		new Thread() {
96  			public void run() {
97  				try {
98  					bundle.stop();
99  				} catch (BundleException e) {
100 					// TODO Auto-generated catch block
101 					e.printStackTrace();
102 				}
103 			}
104 		}.start();
105 	}
106 	
107 }